import {myRequest} from "../../api/myRequest";
import $actions from '../constant/actions'
const _LogicModelManage = 'LogicModelManage';
const LogicModel ={
	//******************************模型配置方法开始*************************************************************************//
	/**
	 * 添加信息
	 * @param record
	 * @returns {Promise<*>}
	 */
	add(record) {
		return myRequest(_LogicModelManage,[{action: $actions.MODEL_ADD, data: [record]}]);
	},
	/**
	 * 更新信息
	 * @param record
	 * @returns {Promise<*>}
	 */
	update(record) {
		return myRequest(_LogicModelManage,[{action: $actions.MODEL_UPDATE, data: [record]}]);
	},

	/**
	 * 删除信息
	 * @param id
	 * @returns {Promise<*>}
	 */
	delete(filter) {
		return myRequest(_LogicModelManage,[{action: $actions.MODEL_DELETE, ...filter}]);
	},
	/**
	 * 删除信息
	 * @param id
	 * @returns {Promise<*>}
	 */
	deleteById(id) {
		return myRequest(_LogicModelManage,[{action: $actions.MODEL_DELETE_BY_ID,id:id}]);
	},

	/**
	 * 批量删除信息
	 * @param ids
	 * @returns {Promise<*>}
	 */
	deleteByIds(ids) {
		return myRequest(_LogicModelManage,[{action: $actions.MODEL_DELETE_BY_IDS, ids: ids}]);
	},
	/**
	 * 查询列表
	 * @param recipient
	 * @returns {Promise<*>}
	 */
	query(filter) {
		let recipient = [{action: $actions.MODEL_QUERY,...filter}]
		return myRequest(_LogicModelManage,recipient);
	},
	/**
	 * 根据id数组进行不分页查询
	 * @param ids id数组
	 * @returns {Promise<*>}
	 */
	queryByIds(ids){
		return myRequest(_LogicModelManage,[{action: $actions.MODEL_QUERY_BY_IDS, ids: ids}]);
	},
	/**
	 * 查询列表
	 * @param recipient
	 * @returns {Promise<*>}
	 */
	queryByPage(pageNumber, pageSize, filter) {
		let recipient = [{action: $actions.MODEL_QUERY_INFO_BY_PAGE, pageNumber: pageNumber, pageSize: pageSize,...filter}]
		return myRequest(_LogicModelManage,recipient);
	},
	/**
	 * 配置注册
	 * @param pointer 注册指针
	 * @param hier  转换成map,如:{"basic":[],"equipment":[]}
	 * @returns {*}
	 */
	initRegister(pointer,hier) {
		let recipient = [{action: $actions.MODEL_INIT_REGISTER,pointer:pointer,hier:[hier]}]
		return myRequest(_LogicModelManage,recipient);
	},
	/**
	 * 配置订阅
	 * @param pointer 订阅指针
	 * @param others 是map,如 {"basic":[]}
	 * @returns {*}
	 */
	initSubscribe(pointer,others) {
		let recipient = [{action: $actions.MODEL_INIT_REGISTER,pointer:pointer,others:others}]
		return myRequest(_LogicModelManage,recipient);
	},
	//******************************模型版本管理方法开始*************************************************************************//
	/**
	 * 版本升级
	 * @className 模型类名
	 * @param version 模型版本号
	 * @returns {Promise<*>}
	 */
	upgrade(className,version) {
		return myRequest(_LogicModelManage,[{action: $actions.MODEL_UPGRADE, className: className, version:version}]);
	},

	/**
	 * 更新信息
	 * @param record
	 * @returns {Promise<*>}
	 */
	published(className,version) {
		return myRequest(_LogicModelManage,[{action: $actions.MODEL_PUBLISHED, className: className, version:version}]);
	},

	/**
	 * 更新信息
	 * @param record
	 * @returns {Promise<*>}
	 */
	unpublished(className,version) {
		return myRequest(_LogicModelManage,[{action: $actions.MODEL_UNPUBLISHED,className: className,version:version}]);
	},
	/**
	 * 不分页包括未发布查询
	 * @param recipient
	 * @returns {Promise<*>}
	 */
	queryIncludeUnpublished(filter) {
		let recipient = [{action: $actions.MODEL_QUERY_INCLUDE_UNPUBLISHED,...filter}]
		return myRequest(_LogicModelManage,recipient);
	},
	/**
	 * 分页包括未发布的查询列表
	 * @param recipient
	 * @returns {Promise<*>}
	 */
	queryIncludeUnpublishedByPage(pageNumber, pageSize, filter) {
		let recipient = [{action: $actions.MODEL_QUERY_INCLUDE_UNPUBLISHED_BY_PAGE, pageNumber: pageNumber, pageSize: pageSize,...filter}]
		return myRequest(_LogicModelManage,recipient);
	},
	//******************************模型摘要方法开始*************************************************************************//
	/**
	 * 简单查询不包括属性或大字段信息
	 * @param filter
	 * @returns {Promise<*>}
	 */
	queryInfo(filter) {
		let recipient = [{action: $actions.MODEL_QUERY_INFO,...filter}]
		return myRequest(_LogicModelManage,recipient);
	},
	/**
	 * 查询列表
	 * @param recipient
	 * @returns {Promise<*>}
	 */
	queryInfoByPage(pageNumber, pageSize, filter) {
		let recipient = [{action: $actions.MODEL_QUERY_INFO_BY_PAGE, pageNumber: pageNumber, pageSize: pageSize,...filter}]
		return myRequest(_LogicModelManage,recipient);
	},
	/**
	 * 简单查询不包括属性或大字段信息
	 * @param filter
	 * @returns {Promise<*>}
	 */
	queryInfoIncludeUnpublished(filter) {
		let recipient = [{action: $actions.MODEL_QUERY_INFO_INCLUDE_UNPUBLISHED,...filter}]
		return myRequest(_LogicModelManage,recipient);
	},

	/**
	 * 分页包括未发布查询列表
	 * @param recipient
	 * @returns {Promise<*>}
	 */
	queryInfoIncludeUnpublishedByPage(pageNumber, pageSize, filter) {
		let recipient = [{action: $actions.MODEL_QUERY_INFO_INCLUDE_UNPUBLISHED_BY_PAGE, pageNumber: pageNumber, pageSize: pageSize,...filter}]
		return myRequest(_LogicModelManage,recipient);
	},
}

export default LogicModel;
